package android;

public class StackOverflow {
	static long res = 0;
	public static int compare(int a,int b){
		return a!=b?a<b?a:b:0;
	}	
	static long factorial(long n){
		if (n>1)return n * factorial(--n);
 		else return n;
	}
	static int power(int i,int n){
		if (n>1) return i * power(i,--n);
		else return i;
	}
	static void invers(int [] a, int n){
		if (n>1) {System.out.print(a[--n]);
					invers(a,n);
		}
		else System.out.println(a[0]);  
	}
	static int secMax(int[] a, int x){
		if (x>=a.length){
			x=0;
			for (int i = 0;i<a.length; ++i){
				if(a[i]>=a[x]) x=i;
			}
			return secMax(a,x);
		}
		else{
			int p = x;
			x=0;
			for (int i = 0; i<a.length; ++i){
					if(a[i]<a[p]&&p!=i&&a[i]>a[x]) x=i;						
			}
			return a[x];
		}
	}
	static int squareRoot(int a, int n){
		if (--a-n<1)return n/2;
		else return squareRoot(a-n,n+=2);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			System.out.println(factorial(5));
			System.out.println(power(5,2));
			int [] arr =new int [10];
			for (int i = 0;i<arr.length; i++){
				arr[i] = i;
			}
			invers(arr,10);
			System.out.println(secMax(arr,10));
			System.out.println(squareRoot(256,1));
			System.out.println(Math.sqrt(256));
			
	}

}
